package com.iap.common.view.control.code
{
	import com.iap.common.model.VectorImage;
	import com.iap.common.model.VectorModel;
	import com.iap.common.view.control.VectorDisplay;
	import com.iap.common.view.control.VectorImageFillerDisplay;
	
	import spark.components.Group;

	public class VectorDisplayCode extends Group
	{
		private static const DEFAULT_WIDTH:uint = 200;
		protected var view:VectorDisplay;

		protected var model:VectorModel;

		public function VectorDisplayCode()
		{
			super();
		}

		public function setSource(model:VectorModel):void
		{
			this.model = model;
			addImages();
		}

		protected function init(view:VectorDisplay):void
		{
			this.view = view;
			addImages();
		}

		private function addImages():void
		{
			if(view == null) return;
			if(model == null) return;
			clearImages();
			for each(var item:VectorImage in model.vectorImages)
			{
				addImage(item);
			}
		}

		private function clearImages():void
		{
			view.main.removeAllElements();
		}

		private function addImage(item:VectorImage):void
		{
			var control:VectorImageFillerDisplay = new VectorImageFillerDisplay();
			control.width = DEFAULT_WIDTH;
			control.height = DEFAULT_WIDTH;
			control.setSource(item, null);
			view.main.addElement(control);
		}
	}
}